package org.spider.thread;

import org.springframework.scheduling.concurrent.ScheduledExecutorTask;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolInit {

    public static void main(String[] args) {
        TaskThreadFactory taskThreadFactory = new TaskThreadFactory("task1");
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                5,
                5,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                taskThreadFactory,
                new ThreadPoolExecutor.AbortPolicy()
        );
        for (int i=0; i<10; i++) {
            threadPoolExecutor.execute(() -> {

            });
        }
        threadPoolExecutor.shutdown();
        ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
        try {
            boolean flag = false;
            do {
                flag = threadPoolExecutor.awaitTermination(500, TimeUnit.MICROSECONDS);
            }while (flag);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        TaskThreadFactory taskThreadFactory2 = new TaskThreadFactory("task2");
        ThreadPoolExecutor threadPoolExecutor2 = new ThreadPoolExecutor(
                5,
                5,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                taskThreadFactory,
                new ThreadPoolExecutor.AbortPolicy()
        );
    }
}
